//app.js


import Util from "utils/util";
import Config from "config";


App({

  globalData: {
    systemInfo: null,
    userInfo: null,
    openId: 1,
    code: null,
    sessionKey: null,
  },


  "Util": Util,
  "Config": Config,



  // 小程序初始化
  onLaunch() {
    const that = this;
    // 获取系统信息
    wx.getSystemInfo({
      success(res) {
        that.globalData.systemInfo = res;
      },
    });
    that.inIt();

  },


  // 小程序初始化
  inIt: function () {
    const that = this;
    that.Util.login() // 登录
      .then((res) => {
        // console.log(res);
        that.globalData.code = res.code;
        return that.Util.getUserInfo();  // 获取用户信息
      })
      .then((res) => {
        // console.log(res);
        that.globalData.userInfo = res.userInfo;
        return that.Util.getOpenIdAndKey(that.globalData.code); // 获取openId 和 access_key
      })
      .then((res) => {
        // console.log(res.data.data.openId); // 后台需要改！
        that.globalData.openId = res.data.data.openId;
      })
      .catch((res) => {
        that.globalData.userRefuse = true;
      })

  },


})